from public.action import *
from public.tools import *
from public.testData import *
testCase = "DBshop0010_处理退货"
# 1.点击处理退货，退货处理“同意退货”，退款金额“2199”。处理意见“同意”。
firefox=getDriver()
openBrowser(firefox,urlAdmin)
logInAdmin(firefox)

adminMenu2(firefox,"销售管理","退货管理")

# 点击退货方式，选择框选择“退货到账户余额”点击“搜索”按钮。
firefox.find_element_by_xpath("(//select)[1]/option[2]").click()
firefox.find_element_by_xpath("//button[@type='submit']").click()
time.sleep(1)

shopid=firefox.find_element_by_xpath("//tbody/tr[2]/td[1]").text
print(shopid)

firefox.find_element_by_xpath("//td[contains(.,'%s')]/following-sibling::td[5]/a[1]"%shopid).click()

firefox.find_element_by_id("refund_price").clear()
s=firefox.find_element_by_xpath("//body").text
# print(s)
l="订单总额:￥ "
r="\nCopyright"
sal=int(reGetString(s,l,r))
print(sal)
firefox.find_element_by_id("refund_price").send_keys(sal)
firefox.find_element_by_id("re_refund_info").send_keys("同意")
# 2.提交处理结果。
firefox.find_element_by_xpath("//button").click()
time.sleep(2)
firefox.quit()
# 3.回到前台界面，点击“用户中心”，退货申请界面，查看退款成功
firefox=getDriver()
openBrowser(firefox,url)
login(firefox,name,password)

firefox.find_element_by_link_text("用户中心").click()
firefox.find_element_by_link_text("退货申请").click()
#断言
firefox.find_element_by_xpath("(//input)[3]").send_keys(shopid)
firefox.find_element_by_xpath("//button[@class='btn btn-small btn-primary']").click()
s=firefox.find_element_by_xpath("//table/tbody/tr/td[4]").text
print(s)

try:
    if s=="退款成功":
        writeLog("%s 测试通过" % testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()

